from pyeasyaccept.gui.ScriptPreviewPanel import ScriptPreviewPanel
import unittest
import wx
import os

"""
This class tests the 'ScriptPreview' panel
@author: Danilo Torres
"""
class ScriptPreviewPanelTest(unittest.TestCase):
    
    LINE_SEPARATOR = os.linesep
    
    """
    This method sets initial information
    """
    def setUp(self):
        self.app = wx.App()
        self.frame = wx.Frame(None, -1)
        self.panel = ScriptPreviewPanel(self.frame, -1)
        
        
    """
    This method tear down informations
    """
    def tearDown(self):
        self.app.Destroy()
        self.frame.Destroy()
        self.panel.Destroy()

    """
    This method runs the successful tests
    """
    def testScriptPreviewPanel(self):
        noText = self.panel.getText()
        
        line1 = "expect 2 soma 1 1"
        self.panel.addScriptLine(line1)
        textLine1 = self.panel.getText()

        line2 = "containsstring \"python\" echo \"py\""
        self.panel.addScriptLine(line2)

        line3 = "echo \"testing\""        
        self.panel.addScriptLine(line3)
        allText = self.panel.getText()
        
        self.panel.clear()
        clearText = self.panel.getText()        
        
        self.assertEquals( noText, "")
        self.assertEquals( textLine1, line1 + self.LINE_SEPARATOR)
        self.assertEquals( allText, line1 + self.LINE_SEPARATOR + line2 + self.LINE_SEPARATOR + line3 + self.LINE_SEPARATOR)

    
if __name__ == '__main__':
    unittest.main() 